const { AsyncSeriesHook } = require("tapable");

class HYCompiler {
  constructor() {
    this.hooks = {
      // parallel: 并行，不会等到上一个事件回调执行结束，才执行下一次事件处理回调
      asyncSeriesHook: new AsyncSeriesHook(["name", "age"]),
    };

    this.hooks.asyncSeriesHook.tapAsync("event1", (name, age, cb) => {
      setTimeout(() => {
        console.log("event1事件执行了", name, age);
        cb();
      }, 2000);
    });

    this.hooks.asyncSeriesHook.tapAsync("event2", (name, age, cb) => {
      setTimeout(() => {
        console.log("event1事件执行了", name, age);
        cb();
      }, 2000);
    });
  }
}

setTimeout(() => {
  const compiler = new HYCompiler();
  compiler.hooks.asyncSeriesHook.callAsync("why", 23, () => {
    console.log("所有任务都执行完成");
  });
}, 0);
